const doc = null;
// const doc = window.document;

function get(key) {
	if (!key || !_has(key)) {
		return null;
	}
	return uni.getStorageSync(key)||{}
	
}

function getObjectAndRemove(key){
	const object=get(key);
	remove(key);
	// if(object){
	// 	return JSON.parse(object);
	// }
	return object;
}


function all() {
	return uni.getStorageInfoSync()
}

function set(key, data, time) {
	if (!key) {
		return;
	}
	uni.setStorageSync(key, data)
}

function remove(key) {
	if (!key || !_has(key)) {
		return;
	}
	uni.removeStorageSync(key)
}

function clearAll() {
	uni.clearStorage()
}

function _has(key) {
	if (!key) {
		return
	}
	let value = uni.getStorageSync(key)
	if (value) {
		return true
	}
	return false
}

const LOGIN_KEY = "X-Token";
const BASE_KEY="base_info";
const USER_INFO="user_info";

function getToken() {
	return get(LOGIN_KEY);
}

function setToken(token) {
	return set(LOGIN_KEY, token)
}

 function getRefreshToken() {
	return get(REFRESH_KEY);
}

function setBaseInfo(baseInfo) {
	return set(BASE_KEY, baseInfo)
}

function getBaseInfo() {
	return get(BASE_KEY);
}
function setUserInfo(userInfo) {
	return set(USER_INFO, userInfo)
}

function getUserInfo() {
	return get(USER_INFO);
}
 
 

export default {
	get,
	getToken,
	setToken,
	getBaseInfo,
	setBaseInfo,
	setUserInfo,
	getUserInfo,
	getRefreshToken,  
	all,
	set,
	remove,
	clearAll,   
	has: _has
};
